#!/bin/awk -f
## Use: awk -f THISFILE tiling_name P Q
# where inflation rate is P + Q * tau
# Additionaly, we do translation by 10000 - as it turns out
# to be necessary for using atoms2nodes.5d and deco DECODB/hbs-inflate2
# and to get discrete-perp shift equivalent to other RH-HBS tilings
BEGIN{
#    print ARGC,ARGV[1],ARGV[2],ARGV[3];
    p=ARGV[2]; q=ARGV[3]; delete ARGV[2]; delete ARGV[3]; ARGC-=2;
    inf5[1,3]=-q; inf5[1,4]=-q;
    inf5[2,4]=-q; inf5[2,5]=-q;
    inf5[3,5]=-q; inf5[3,1]=-q;
    inf5[4,1]=-q; inf5[4,2]=-q;
    inf5[5,2]=-q; inf5[5,3]=-q;
    for(i=1;i<=5;i++){inf5[i,i]=p};
#    print p,q;
}
FNR!=3{
  split($0,a);
#  inflate(a);
  inflate(a);
  if(FNR>3){a[1]++}; # shift along discrete perp by 1
  dpbound(a);
  for(i=1;i<=5;i++){printf("%1i ",a[i])};
  print "";
}
FNR==3{print}

function inflate(a){
  for(i=1;i<=5;i++){b[i]=a[i];a[i]=0};
  for(i=1;i<=5;i++){
    for(j=1;j<=5;j++){
      a[j]+=b[i]*inf5[i,j];
    }
  }
}
function dpbound(a){
  sum=0;for(i=1;i<=5;i++){sum+=a[i]};
  s=1;
  if(sum<0){s=-1;sum=-sum};
  k=sum%5;
  l=(sum-k)/5;
  if(sum-5*l>2){l++};
#  print s*sum,s*l>"/dev/stderr";
  for(i=1;i<=5;i++){a[i]-=s*l};
}
